// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso;

import org.lwjgl.opengl.ARBShaderObjects;
import zombie.core.SpriteRenderer;
import zombie.core.opengl.RenderThread;
import zombie.core.opengl.ShaderProgram;

public final class TallFenceShader {
    public static final TallFenceShader instance = new TallFenceShader();
    private ShaderProgram shaderProgram;
    private int u_alpha;
    private int u_outlineColor;
    private int u_stepSize;

    public void initShader() {
        this.shaderProgram = ShaderProgram.createShaderProgram("tallFence", false, true);
        if (this.shaderProgram.isCompiled()) {
            this.u_alpha = ARBShaderObjects.glGetUniformLocationARB(this.shaderProgram.getShaderID(), "u_alpha");
            this.u_stepSize = ARBShaderObjects.glGetUniformLocationARB(this.shaderProgram.getShaderID(), "u_stepSize");
            this.u_outlineColor = ARBShaderObjects.glGetUniformLocationARB(this.shaderProgram.getShaderID(), "u_outlineColor");
            ARBShaderObjects.glUseProgramObjectARB(this.shaderProgram.getShaderID());
            ARBShaderObjects.glUniform2fARB(this.u_stepSize, 0.001F, 0.001F);
            ARBShaderObjects.glUseProgramObjectARB(0);
        }
    }

    public void setAlpha(float alpha) {
        SpriteRenderer.instance.ShaderUpdate1f(this.shaderProgram.getShaderID(), this.u_alpha, alpha);
    }

    public void setOutlineColor(float r, float g, float b, float a) {
        SpriteRenderer.instance.ShaderUpdate4f(this.shaderProgram.getShaderID(), this.u_outlineColor, r, g, b, a);
    }

    public void setStepSize(float stepSize, int texWidth, int texHeight) {
        SpriteRenderer.instance.ShaderUpdate2f(this.shaderProgram.getShaderID(), this.u_stepSize, stepSize / (float)texWidth, stepSize / (float)texHeight);
    }

    public boolean StartShader() {
        if (this.shaderProgram == null) {
            RenderThread.invokeOnRenderContext(this::initShader);
        }

        if (this.shaderProgram.isCompiled()) {
            zombie.IndieGL.StartShader(this.shaderProgram.getShaderID(), 0);
            return true;
        } else {
            return false;
        }
    }
}
